#include "MovingLeastSquaresModel.h"

#include "core/AppDirectory.h"

namespace {
const QString UserFilename = "pcl.moving_least_squares_model.json";
}

MovingLeastSquaresModel::MovingLeastSquaresModel()
    : BasePclModel()
{
    setPclHelpPage("https://pcl.readthedocs.io/projects/tutorials/en/master/resampling.html");
}

MovingLeastSquaresModel& MovingLeastSquaresModel::get()
{
    static MovingLeastSquaresModel instance;
    if (instance.filename().isEmpty()) {
        instance.setFilename(AppDirectory::get().getAppDocFile(UserFilename));
        instance.load();
    }
    return instance;
}

void MovingLeastSquaresModel::fromJson(const QJsonObject& json, QStringList& errorList)
{
    BasePclModel::fromJson(json, errorList);

    pcdFile_ = json["pcdFile"].toString(pcdFile_);
    polynomialOrder_ = json["polynomialOrder"].toInt(polynomialOrder_);
    radiusSearch_ = json["radiusSearch"].toDouble(radiusSearch_);
}

QJsonObject MovingLeastSquaresModel::toJson() const
{
    QJsonObject json = BasePclModel::toJson();

    json.insert("pcdFile", QJsonValue(pcdFile_));
    json.insert("polynomialOrder", QJsonValue(polynomialOrder_));
    json.insert("radiusSearch", QJsonValue(radiusSearch_));

    return json;
}
